package com.example.factory.api.dto;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

/**
 * @author Lei Tao
 */
public abstract class PagingRequest {
    // base-one
    private int pageNumber = 1;

    private int pageSize = 10;


    public PagingRequest() {
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Pageable pageable() {
        if (pageNumber <= 0) {
            return PageRequest.of(0, pageSize);
        }
        // spring jpa pageNumber base-zero
        return PageRequest.of(pageNumber - 1, pageSize);
    }
}
